#pragma once

#include "../can_adapter.h"
#include "../can_transreceiver.h"
#include "b30_001.h"
#include "muduo/net/EventLoop.h"
#include "muduo/net/EventLoopThread.h"
#include <atomic>
#include <unordered_map>
namespace sensor::radar {
class CanTransreceiver;
class ZiyanCanAdapter : public CanAdapter {
public:
    explicit ZiyanCanAdapter(std::unordered_map<std::string, std::shared_ptr<CanTransreceiver>> devs);

    virtual void onReceiveCanMessage(const std::string& dev, int fid, muduo::net::Buffer& buffer) override;
    virtual void onReceiveGnssMessage(const interface::msg::Gnss::SharedPtr msg) override;
    virtual void onReceiveInformationMessage(const interface::msg::CarInformation msg) override;
    double degreesToRadians(double degrees);
    std::string printObject(const interface::msg::Object& object);

private:
    using CanMessageUnpackFunction = std::function<void(const std::string& dev, int fid, muduo::net::Buffer& buffer)>;
    std::map<int, CanMessageUnpackFunction> message_unpack_table_;
    static std::unordered_map<int, int> ZiyanObjectTypeMap;

    std::mutex radar0MapLock_;
    std::mutex radar2MapLock_;
    std::mutex radar3MapLock_;

    std::map<int, std::pair<u_int64_t, interface::msg::Object>> radar0ObjectsMap;
    std::map<int, std::pair<u_int64_t, interface::msg::Object>> radar2ObjectsMap;
    std::map<int, std::pair<u_int64_t, interface::msg::Object>> radar3ObjectsMap;
};

}